<%--
  Created by IntelliJ IDEA.
  User: fengdefangxiang
  Date: 2022/2/9
  Time: 11:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>项目信息</title>
    <%@ include file="/web/header.jsp" %>
</head>
<body>
<div class="layui-collapse">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">项目信息--查询条件</h2>
        <div class="layui-colla-content layui-show">
            <fieldset class="layui-elem-field layui-field-title"
                      style="margin: 10px">
                <legend>项目信息--查询条件</legend>
                <div class="layui-field-box">
                    <form class="layui-form layui-form-pane">
                        <div class="layui-form-item">
                            <label class="layui-form-label">项目编号</label>
                            <div class="layui-input-inline">
                                <label>
                                    <input type="text" name="code" autocomplete="off"
                                           class="layui-input">
                                </label>
                            </div>
                            <label class="layui-form-label">项目名称</label>
                            <div class="layui-input-inline">
                                <label>
                                    <input type="text" name="name" autocomplete="off"
                                           class="layui-input">
                                </label>
                            </div>
                            &nbsp;&nbsp;&nbsp;
                            <span class="layui-form-item">
								<input type="button" value="查询" class="layui-btn layui-btn-radius layui-btn-warm"
                                       lay-submit lay-filter="search"> <input type="reset"
                                                                              value="重置"
                                                                              class="layui-btn layui-btn-radius layui-btn-warm">
								<input type="button" value="添加" onclick="openAdd()"
                                       class="layui-btn layui-btn-radius layui-btn-warm">
							</span>
                        </div>
                        <!-- 						<input type="hidden" name="action" value="list"> -->
                        <input type="hidden" name="action" value="page">

                        <!-- 						分页参数 加之分页参数查询当前页面数据 -->
                        <input type="hidden" name="pageIndex" value="1">
                        <input type="hidden" name="pageLimit" value="10">
                    </form>
                </div>
            </fieldset>
        </div>
    </div>
</div>
<table class="layui-table">
    <colgroup>
        <col width="5%">
        <col width="10%">
        <col width="15%">
        <col width="12%">
        <col width="12%">
    </colgroup>
    <thead>
    <tr>
        <th>序号</th>
        <th>项目编号</th>
        <th>项目名称</th>
        <th>开始时间</th>
        <th>结束时间</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="tbody">

    </tbody>
</table>

<!-- 分页 -->
<div id="pageInfo" style="text-align:right; padding-right:30px"></div>

<script type="text/javascript">
    formOnSubmit("search", "/ProjectServlet", "json", function (data) {
        var count = data.count
        var curr = $("input[name='pageIndex']").val()
        var limit = $("input[name='pageLimit']").val()
        pageInfo("pageInfo", count, curr, limit, function (obj, first) {
            $("input[name='pageIndex']").val(obj.curr)
            $("input[name='pageLimit']").val(obj.limit)
            if (!first) {refresh()}
        })

        var list = data.list
        var html = ""
        var tpl = $("#tradd").html()
        $.each(list, function (i, dom) {
            var startTime = ""
            var endTime = ""
            if (dom.startTime != null)
                startTime = dom.startTime
            if (dom.endTime != null)
                endTime = dom.endTime
            var d = {
                id: (i + 1 + (curr - 1) * limit),
                code: dom.code,
                name: dom.name,
                startTime: startTime,
                endTime: endTime
            }
            html += laytpl(tpl).render(d)
        })
        $("tbody").html(html)
        layer.msg("查询成功", {time: 1000, icon: 6})
    })
    refresh();

    function openAdd() {//添加
        layerOpen("/web/page/project/add.jsp", refresh)
    }

    function del(code) {
        layerConfig(function () {
            ajax("/ProjectServlet", {code: code, action: 'del'}, 'text', function (data) {
                if (data == "1") {
                    layer.msg("删除成功", {shift: -1, time: 2000, icon: 6}, refresh)
                } else {
                    layer.msg("删除失败", {shift: -1, time: 2000, icon: 5})
                }
            })
        }, "确认删除此项目信息?")
    }

    function openUpdName(code) {
        layer.prompt({formType: 0, title: '更改项目名称',}, function (value, index) {
            ajax("/ProjectServlet", {code: code, name: value, action: "updName"}, "text", function (data) {
                if (data == "1") {
                    layer.msg("项目名称更改成功", {shift: -1, time: 2000, icon: 6}, refresh)
                } else {
                    layer.msg("项目名称更改失败", {shift: -1, time: 2000, icon: 5})
                }
            })
            layer.close(index)
        })
    }

    function openUpdTime(code) {
        layerOpen("/web/page/project/upd.jsp?code=" + code, refresh)
    }

</script>


<script type="text/html" id="tradd">
    <tr>
        <td>{{d.id}}</td>
        <td>{{d.code}}</td>
        <td>{{d.name}}</td>
        <td>{{d.startTime}}</td>
        <td>{{d.endTime}}</td>
        <td>
            <a href="javascript:del('{{d.code}}')" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-danger">
                <i class="layui-icon layui-icon-delete"></i></a>
            <a href="javascript:openUpdName('{{d.code}}')"
               class="layui-btn layui-btn-sm layui-btn-radius layui-btn-normal">
                <i class="layui-icon layui-icon-edit"></i>项目名称</a>
            <a href="javascript:openUpdTime('{{d.code}}')"
               class="layui-btn layui-btn-sm layui-btn-radius layui-btn-normal">
                <i class="layui-icon layui-icon-edit"></i>项目时间</a>
        </td>
    </tr>
</script>
</body>
</html>
